package com.huanguo.dashboard.viewmodel

import android.view.View
import android.widget.Toast
import com.team.childapp.base.viewmodel.BaseViewModel
import com.huanguo.dashboard.bean.DashBoardDataBean
import com.team.childapp.util.thread.bgThreadRun
import java.util.Random

/**
 *AUTHOR:suichengju
 *DATE:2022/9/1
 *INTRODUCE:测试ViewModel,模拟网络请求数据，在实际业务开发中应是真实的，请求成功或失败，可以使用LiveData进行返回至
 * UI层，或者直接回调方式
 */
class MainDashBoardViewModel : BaseViewModel() {

    lateinit var mboardData: DashBoardDataBean

    var clickListener = View.OnClickListener {

        Toast.makeText(it.context, "设置", Toast.LENGTH_SHORT).show()
    }

    fun initMboardData() {
        mboardData = DashBoardDataBean()
        bgThreadRun {
            while (true) {
                mboardData.sprayState = Random().nextInt(10) % 2 == 0
                mboardData.manureUseUpAlarm = Random().nextInt(10) % 2 == 0
                mboardData.manureBlockAlarm= Random().nextInt(10) % 2 == 0
                mboardData.enginePreheatState= Random().nextInt(10) % 2 == 0
                mboardData.engineFaultState= Random().nextInt(10) % 2 == 0
                mboardData.oneTurnStateSwich= Random().nextInt(10) % 2 == 0
                mboardData.oilPressureAlarm= Random().nextInt(10) % 2 == 0
                mboardData.waterTemperatureAlarm = Random().nextInt(10) % 2 == 0
                mboardData.setEngineWorkHours(Random().nextDouble())
                mboardData.quantityBunkers= Random().nextInt()
                mboardData.interpolationWorkSwichState = Random().nextInt(10) % 2 == 0
                mboardData.riceShootUseUpAlarm = Random().nextInt(10) % 2 == 0
                mboardData.cellVoltage = Random().nextDouble()
                Thread.sleep(2000)
            }
        }
    }
}